<!--  -->
<template>

  <div class="update-birthday">
    <van-nav-bar title="修改单位" right-text="完成" left-text="取消" 
      @click-left="$emit('close')" @click-right="onConfirm" />

    <div class="name-field-wrap">
      <van-form>
        <van-field v-model="department" rows="2" autosize type="textarea" placeholder="请输入单位"
          :rules="[{ required: true, message: '请输入单位名称', trigger: 'onBlur' }]" />
      </van-form>
    </div>
  </div>
</template>

<script>
import { updateUser } from '@/api/user'
export default {
  name:'UpdateBirthday',
  components: {},
  props:{
    value:{
      type:String,
      require:true
    },
    user:Object,
  },
  data() {
    return {
      department: this.value,
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    async onConfirm(value) {

      this.$toast.loading({
        message: '保存中',
        forbidClick: true  //禁止背景点击
      })

      try {
        const { data } = await updateUser({
          "user_name": this.user.user_name,
          "phonenumber": this.user.phonenumber,
          "department": this.department,
        })

        if (data.code != "200") {
          this.$message.fail('修改失败！' + data.msg);
        } else {
          this.$toast.success(data.msg);
          //更新成功->修改父组件->关闭弹出层
          this.$emit('input',this.department);
          this.$emit('close')
        }
      } catch (error) {
        if (error) {
          this.$toast.fail('修改失败');
        }
      }

    }
  }
}

</script>
<style lang='less' scoped>
.name-field-wrap{
  padding: 10px;
}

</style>